package com.dup.jxlh.admin.service.impl;

import com.dup.jxlh.admin.entities.model.Organ;
import com.dup.jxlh.admin.mapper.OrganMapper;
import com.dup.jxlh.admin.service.OrganService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.ArrayList;

@Service("organServiceImpl")
public class OrganServiceImpl implements OrganService {
    @Resource
    private OrganMapper organMapper;

    @Override
    public ArrayList<Organ> getOrganList(BigInteger companyId) {
        return organMapper.getOrganList(companyId);
    }

    @Override
    @Async
    public Boolean addOrgan(BigInteger companyId, String name) {
        if (organMapper.getOrganByName(companyId, name) != null) {
            return true;
        }
        if (organMapper.addOrgan(companyId, name) == 1) {
            return true;
        }
        return false;
    }
}
